import random

import pyautogui
import cv2

def judgment(Serial_Nonum):
    """
    cv2.minMaxLoc返回4个数值，最小值，最大值，最小值坐标，最大值坐标，最小值越小，越相识
    :param num:
    :return:
    """
    # 获取屏幕截图
    pyautogui.screenshot().save('./pic/screenshot.png')
    # 加载屏幕截图
    img = cv2.imread("./pic/screenshot.png")
    # 图像模板判断
    if Serial_Nonum == 1:
        # 开始
        img_target = cv2.imread(r'./pic/start.png')
        result = cv2.matchTemplate(img, img_target, cv2.TM_SQDIFF_NORMED)
        similar = cv2.minMaxLoc(result)[0]
        if similar <= 0.07:
            print('开始')
            Serial_Nonum = [1]
            return Serial_Nonum, img, img_target, result, similar
        else:
            print('Num 不为1 or 2')
            return [0]
    elif Serial_Nonum == 2:
        # 结束
        img_target2 = cv2.imread(r'pic/game_end.png')
        result2 = cv2.matchTemplate(img, img_target2, cv2.TM_SQDIFF_NORMED)
        similar2 = cv2.minMaxLoc(result2)[0]
        if similar2 <= 0.07:
            print('结束')
            Serial_Nonum = [2]
            return Serial_Nonum, img, img_target2, result2, similar2
        else:
            print('Num 不为2 or 1')
            return [0]
    elif Serial_Nonum == 3:
        print("执行成功")
        return [0]
    else:
        print("查找目标ing")
        count = random.randint(1, 2)
        return [count]